package com.njtoyo.taxi.admin.mapper.master.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.library.Const;
import com.njtoyo.taxi.admin.mapper.master.entity.Driver;
import com.njtoyo.taxi.admin.rest.export.driver.DriverListData;
import com.njtoyo.taxi.admin.rest.pojo.dto.DriverTaxiVehicleInfo;
import com.njtoyo.taxi.admin.rest.pojo.dto.DriverVehicleInfo;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.DriverCantonCompanyVo;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.DriverListPresenter;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.QuerySpecialRewardRulePickRidePresenter;
import com.njtoyo.taxi.admin.rest.presenter.data.data_analysis.DriverDataPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.DriverExportWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.DriverQueryWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.data.data_analysis.DriverDataWrapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Dell
 * @since 2021-07-13
 */
@Repository
@DS(Const.PRIMARY_DS)
public interface DriverMapper extends BaseMapper<Driver> {
    @Select("SELECT id FROM driver WHERE is_leave = 0 AND driver_region_id = #{driverRegionId}")
    List<Long> findDriverIdsByDriverRegionId(@Param("driverRegionId") Long driverRegionId);

    @Select("SELECT d.id FROM driver d LEFT JOIN taxi t ON d.taxi_id = t.id WHERE d.is_leave = 0 AND t.company_id = #{companyId}")
    List<Long> findDriverIdsByCompanyId(@Param("companyId") Long companyId);

    @Select("SELECT id FROM driver WHERE is_leave = 0")
    List<Long> findDriverIdsAll();

    Long getTotalCount(@Param("cantonIds") List<Long> cantonIds, @Param("companyIds") List<Long> companyIds);

    Long getTotalCount(@Param("cantonIds") List<Long> cantonIds, @Param("companyIds") List<Long> companyIds, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    // 根据公司ids获取司机列表
    List<Driver> getDriverListByCompanyIds(@Param("companyIds") List<Long> companyIds);

    //查询司机手机号
    String selectMobileNumber(@Param("mobileNumber") String mobileNumber);

    //司机列表
    Page<DriverListPresenter> selectDriverPageList(DriverQueryWrapper wrapper);

    Page<DriverDataPresenter> getDriverDateList(DriverDataWrapper wrapper);

    List<DriverListData> selectDriverList(DriverExportWrapper wrapper);

    //司机批量清除缓存
    List<Driver> selectBatchClearCache(@Param("ids") List<Long> ids);

    //司机批量解封号
    List<Driver> selectBatchIsBlock(@Param("ids") List<Long> ids);


    //通过车辆查询司机id
    List<Long> selectDriverByIds(Long taxiId);

    List<DriverCantonCompanyVo> selectDriverCantonCompanyList(@Param("driverIds") Set<Long> driverIds);

    List<QuerySpecialRewardRulePickRidePresenter> pickRideRank(@Param("cantonId") Long cantonId, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);

    List<DriverListPresenter> getDriverInfoByIds(@Param("driverIds") List<Long> ids);

    List<Map<String, Object>> getRideJoinDriver(@Param("callId") String callId);

    Page<Long> getDriverIdPage(DriverDataWrapper wrapper);

    BigDecimal getDriverBalance(@Param("driverId") Long driverId);

    List<Long> queryDriverIdByList(@Param("cans") List<Long> cans, @Param("coms") List<Long> coms);

    List<DriverVehicleInfo> findDriverVehicleInfoByDriverId(@Param("driverId")Long id);

    List<DriverTaxiVehicleInfo> getBindTaxiInfoByDriverId(@Param("driverId")Long driverId);
}
